home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 85 / CD Actual 85 Febrero 2004.iso / Experto / Apache / apache_2.0.48-win32-x86-no_ssl.msi / Data.Cab / F251731_apr_allocator.h < prev    next >
Encoding:
C/C++ Source or Header  |  2003-03-07  |  7.6 KB  |  209 lines

  1. /* ====================================================================
  2.  * The Apache Software License, Version 1.1
  3.  *
  4.  * Copyright (c) 2000-2003 The Apache Software Foundation.  All rights
  5.  * reserved.
  6.  *
  7.  * Redistribution and use in source and binary forms, with or without
  8.  * modification, are permitted provided that the following conditions
  9.  * are met:
  10.  *
  11.  * 1. Redistributions of source code must retain the above copyright
  12.  *    notice, this list of conditions and the following disclaimer.
  13.  *
  14.  * 2. Redistributions in binary form must reproduce the above copyright
  15.  *    notice, this list of conditions and the following disclaimer in
  16.  *    the documentation and/or other materials provided with the
  17.  *    distribution.
  18.  *
  19.  * 3. The end-user documentation included with the redistribution,
  20.  *    if any, must include the following acknowledgment:
  21.  *       "This product includes software developed by the
  22.  *        Apache Software Foundation (http://www.apache.org/)."
  23.  *    Alternately, this acknowledgment may appear in the software itself,
  24.  *    if and wherever such third-party acknowledgments normally appear.
  25.  *
  26.  * 4. The names "Apache" and "Apache Software Foundation" must
  27.  *    not be used to endorse or promote products derived from this
  28.  *    software without prior written permission. For written
  29.  *    permission, please contact apache@apache.org.
  30.  *
  31.  * 5. Products derived from this software may not be called "Apache",
  32.  *    nor may "Apache" appear in their name, without prior written
  33.  *    permission of the Apache Software Foundation.
  34.  *
  35.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  36.  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  37.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  38.  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  39.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  40.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41.  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  42.  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  43.  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  44.  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  45.  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  46.  * SUCH DAMAGE.
  47.  * ====================================================================
  48.  *
  49.  * This software consists of voluntary contributions made by many
  50.  * individuals on behalf of the Apache Software Foundation.  For more
  51.  * information on the Apache Software Foundation, please see
  52.  * <http://www.apache.org/>.
  53.  */
  54.  
  55. #ifndef APR_ALLOCATOR_H
  56. #define APR_ALLOCATOR_H
  57.  
  58. /**
  59.  * @file apr_allocator.h
  60.  * @brief APR Internal Memory Allocation
  61.  */
  62.  
  63. #include "apr.h"
  64. #include "apr_errno.h"
  65. #define APR_WANT_MEMFUNC /**< For no good reason? */
  66. #include "apr_want.h"
  67.  
  68. #ifdef __cplusplus
  69. extern "C" {
  70. #endif
  71.  
  72. /**
  73.  * @defgroup apr_allocator Internal Memory Allocation
  74.  * @ingroup APR 
  75.  * @{
  76.  */
  77.  
  78. /** the allocator structure */
  79. typedef struct apr_allocator_t apr_allocator_t;
  80. /** the structure which holds information about the allocation */
  81. typedef struct apr_memnode_t apr_memnode_t;
  82.  
  83. /** basic memory node structure */
  84. struct apr_memnode_t {
  85.     apr_memnode_t *next;            /**< next memnode */
  86.     apr_memnode_t **ref;            /**< reference to self */
  87.     apr_uint32_t   index;           /**< size */
  88.     apr_uint32_t   free_index;      /**< how much free */
  89.     char          *first_avail;     /**< pointer to first free memory */
  90.     char          *endp;            /**< pointer to end of free memory */
  91. };
  92.  
  93. /** The base size of a memory node - aligned.  */
  94. #define APR_MEMNODE_T_SIZE APR_ALIGN_DEFAULT(sizeof(apr_memnode_t))
  95.  
  96. /** Symbolic constants */
  97. #define APR_ALLOCATOR_MAX_FREE_UNLIMITED 0
  98.  
  99. /**
  100.  * Create a new allocator
  101.  * @param allocator The allocator we have just created.
  102.  *
  103.  */
  104. APR_DECLARE(apr_status_t) apr_allocator_create(apr_allocator_t **allocator);
  105.  
  106. /**
  107.  * Destroy an allocator
  108.  * @param allocator The allocator to be destroyed
  109.  * @remark Any memnodes not given back to the allocator prior to destroying
  110.  *         will _not_ be free()d.
  111.  */
  112. APR_DECLARE(void) apr_allocator_destroy(apr_allocator_t *allocator);
  113.  
  114. /**
  115.  * Allocate a block of mem from the allocator
  116.  * @param allocator The allocator to allocate from
  117.  * @param size The size of the mem to allocate (excluding the
  118.  *        memnode structure)
  119.  */
  120. APR_DECLARE(apr_memnode_t *) apr_allocator_alloc(apr_allocator_t *allocator,
  121.                                                  apr_size_t size);
  122.  
  123. /**
  124.  * Free a block of mem, giving it back to the allocator
  125.  * @param allocator The allocator to give the mem back to
  126.  * @param memnode The memory node to return
  127.  */
  128. APR_DECLARE(void) apr_allocator_free(apr_allocator_t *allocator,
  129.                                      apr_memnode_t *memnode);
  130.  
  131. #include "apr_pools.h"
  132.  
  133. /**
  134.  * Set the owner of the allocator
  135.  * @param allocator The allocator to set the owner for
  136.  * @param pool The pool that is to own the allocator
  137.  * @remark Typically pool is the highest level pool using the allocator
  138.  */
  139. /*
  140.  * XXX: see if we can come up with something a bit better.  Currently
  141.  * you can make a pool an owner, but if the pool doesn't use the allocator
  142.  * the allocator will never be destroyed.
  143.  */
  144. APR_DECLARE(void) apr_allocator_owner_set(apr_allocator_t *allocator,
  145.                                           apr_pool_t *pool);
  146.  
  147. /** @deprecated @see apr_allocator_owner_set */
  148. APR_DECLARE(void) apr_allocator_set_owner(apr_allocator_t *allocator,
  149.                                           apr_pool_t *pool);
  150.  
  151. /**
  152.  * Get the current owner of the allocator
  153.  * @param allocator The allocator to get the owner from
  154.  */
  155. APR_DECLARE(apr_pool_t *) apr_allocator_owner_get(apr_allocator_t *allocator);
  156.  
  157. /** @deprecated @see apr_allocator_owner_get */
  158. APR_DECLARE(apr_pool_t *) apr_allocator_get_owner(
  159.                                   apr_allocator_t *allocator);
  160.  
  161. /**
  162.  * Set the current threshold at which the allocator should start
  163.  * giving blocks back to the system.
  164.  * @param allocator The allocator the set the threshold on
  165.  * @param size The threshold.  0 == unlimited.
  166.  */
  167. APR_DECLARE(void) apr_allocator_max_free_set(apr_allocator_t *allocator,
  168.                                              apr_size_t size);
  169.  
  170. /** @deprecated @see apr_allocator_max_free_set */
  171. APR_DECLARE(void) apr_allocator_set_max_free(apr_allocator_t *allocator,
  172.                                              apr_size_t size);
  173.  
  174. #include "apr_thread_mutex.h"
  175.  
  176. #if APR_HAS_THREADS
  177. /**
  178.  * Set a mutex for the allocator to use
  179.  * @param allocator The allocator to set the mutex for
  180.  * @param mutex The mutex
  181.  */
  182. APR_DECLARE(void) apr_allocator_mutex_set(apr_allocator_t *allocator,
  183.                                           apr_thread_mutex_t *mutex);
  184.  
  185. /** @deprecated @see apr_allocator_mutex_set */
  186. APR_DECLARE(void) apr_allocator_set_mutex(apr_allocator_t *allocator,
  187.                                           apr_thread_mutex_t *mutex);
  188.  
  189. /**
  190.  * Get the mutex currently set for the allocator
  191.  * @param allocator The allocator
  192.  */
  193. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_mutex_get(
  194.                                       apr_allocator_t *allocator);
  195.  
  196. /** @deprecated @see apr_allocator_mutex_get */
  197. APR_DECLARE(apr_thread_mutex_t *) apr_allocator_get_mutex(
  198.                                       apr_allocator_t *allocator);
  199.  
  200. #endif /* APR_HAS_THREADS */
  201.  
  202. /** @} */
  203.  
  204. #ifdef __cplusplus
  205. }
  206. #endif
  207.  
  208. #endif /* !APR_ALLOCATOR_H */
  209.